/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ocumed.presentation.termin;

import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.*;
import java.awt.*;
import javax.swing.border.MatteBorder;


/**
 *
 * @author apr3455
 */
public class KalenderCellRenderer extends DefaultTableCellRenderer {
  Color m_color = null;  
  TerminKalender m_tableModel = null;
  boolean test = false;
  JPanel[][] m_panels = null;
  JLabel[][] m_labels = null;
  MatteBorder m_b = new MatteBorder(1, 0, 0, 0, new Color(0,0,0));
  
  public KalenderCellRenderer(TerminKalender tableModel){
      int row = tableModel.getRowCount();
      int col = tableModel.getColumnCount();
      Boolean isFullHour = false;
      m_tableModel = tableModel;
      m_tableModel.getColumnCount();
      m_labels = new JLabel[row][col];
      m_panels = new JPanel[row][col];
      for(int i = 0; i  < row; i++){
          for(int e = 0; e < col; e++){
              m_labels[i][e] = new JLabel((String) tableModel.getValueAt(i, e));
              m_panels[i][e] = new JPanel();
              m_panels[i][e].add(m_labels[i][e]);
              m_panels[i][e].setLayout(new GridLayout(1,0));
              isFullHour = m_labels[i][0].getText().substring(3, 5).equals("00");
              if(isFullHour){
                  m_panels[i][e].setBorder(m_b);
              }
              
          }
      }
  }
  
  @Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
      String v = " " + (String) value;
      m_labels[row][column].setText(v);
      if(isSelected == false){
          String val = (String) m_tableModel.getValueAt(row, column);
              if(m_tableModel.ordinationsZeit(row, column) == true && m_tableModel.fehlZeit(row, column) == false){
                  if(val.equals("") == true){
                      m_panels[row][column].setBackground(new Color(153,255,153));
                  } else {
                      m_panels[row][column].setBackground(new Color(255,153,153));
                  }
              } else {
                  m_panels[row][column].setBackground(new Color(245,245,245));
              }
      } else if(column > 0) {
          if(value.equals("") == true && m_tableModel.ordinationsZeit(row, column) == true && m_tableModel.fehlZeit(row, column) == false){
              m_panels[row][column].setBackground(new Color(255,200,200));
          } else if(!value.equals("")) {
              m_panels[row][column].setBackground(new Color(255,200,200));
          }
      }
      return m_panels[row][column];
  }
}
